package com.easy.demo;

import com.easy.demo.demos.web.service.UserService;
import com.easy.activiti.ext.IActivitiCoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhouchuang
 * @date 2024-10-31 23:14:02
 */
@Service
public class ActivitiCoreService implements IActivitiCoreService {

    @Autowired
    private UserService userService;

    @Override
    public AuthConfigServer authConfigServer() {
        return new AuthConfigServer() {
            @Override
            public List<AuthConfigServer.User> users(User user) {
                return userService.users().stream().map(t->new AuthConfigServer.User(t.getUsername(),t.getRealName(),t.getRoles().stream().map(t2->t2.getCode()).collect(Collectors.toList()))).collect(Collectors.toList());
            }

            @Override
            public AuthConfigServer.User username(String username) {
                com.easy.demo.demos.web.vo.User user = userService.byUserName(username);
                if(user!=null){
                    return new AuthConfigServer.User(user.getUsername(),user.getRealName(),user.getRoles().stream().map(t2->t2.getCode()).collect(Collectors.toList()));
                }
                return null;
            }

            @Override
            public User loginUser() {
                com.easy.demo.demos.web.vo.User user =  userService.me();
                if(user!=null){
                    return new AuthConfigServer.User(user.getUsername(),user.getRealName(),user.getRoles().stream().map(t2->t2.getCode()).collect(Collectors.toList()));
                }
                return null;
            }
            @Override
            public List<Org> orgs(Org org) {
                return null;
            }
        };
    }
}
